package cn.com.zte.ngbc.dao.mybatis.dynamicsql.node;

import org.dom4j.Element;

import cn.com.zte.common.util.StringUtil;
import cn.com.zte.ngbc.dao.mybatis.dynamicsql.DynamicContext;
import cn.com.zte.ngbc.frw.model.sql.dynamic.IfSqlNode;

public class IfSqlNodeHandler
  implements SqlNodeHandler
{
  private IfSqlNode _if;
  
  public IfSqlNodeHandler(IfSqlNode _if)
  {
    this._if = _if;
  }
  
  public String process(DynamicContext context)
  {
    if (StringUtil.isEmpty(this._if.getTest())) {
      throw new IllegalArgumentException("if节点不能为空");
    }
    Element selectEle=  context.selectEle;
    Element ifEle=  selectEle.addElement("if");
    ifEle.addAttribute("test",this._if.getTest());
    context.selectEle=ifEle;
    ifEle.addCDATA(" and ");
   String abc=  context.getChildSql(this._if.getLogic(), null);
   context.selectEle=selectEle;
    return abc;
  }
}
